from typing import Tuple

from common_bind_service.context_utils.context_utils import ContextUtils


def check_upperpc_callid(upperpc: str, callid: str) -> Tuple[bool, str]:
    """校验上位机编码与callid是否正确, 是否是mg系统给的"""

    is_upperpc_ok = False
    is_callid_ok = False
    for device_item in ContextUtils.get_device_code_info_dict().values():
        if device_item.get('上位机编码') == upperpc:
            is_upperpc_ok = True
        if device_item.get('认证id') == callid:
            is_callid_ok = True

    if not is_upperpc_ok:
        return False, '上位机编码错误'
    if not is_callid_ok:
        return False, '认证id错误'
    return True, ''

